package com.ihisun.tmhcms.controller.osscontroller;

import com.ihisun.tmhcms.core.service.ossservice.ImageService;
import com.ihisun.tmhcms.utils.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
@Slf4j
@Api(tags = "oss相关Api")
@RestController
@RequestMapping("/oss")

public class OssController {
    @Resource
    ImageService imageService;

    /**
     * 全局图片路径访问中转站
     *
     * @param response
     * @param request
     */
    @GetMapping(value = "/getRealImageUrl")
    @ApiOperation(value = "全局图片路径访问中转站")
    public void getRealImageUrl(HttpServletResponse response, HttpServletRequest request) {
        // 获取图片真实地址数据信息，处理追加的后缀数据信息
        String actionUrl = request.getParameter("realUrl");
        log.info("----------------------"+actionUrl);
        imageService.getRealImageUrl(response, actionUrl);
    }

    /**
     * 获取oss签名
     *
     * @param businessCode
     * @return
     */
    @GetMapping(value = "/getOssSignForWeb")
    @ResponseBody
    @ApiOperation(value = "获取oss签名")
    public ResponseVo getOssSignForWeb(@RequestParam("businessCode") String businessCode) throws Exception {
        Map<String, String> ossSignForWeb = imageService.getOssSignForWeb(businessCode);
        return ResponseVo.ok(ossSignForWeb);
    }


}
